home *** CD-ROM | disk | FTP | other *** search
- Path: news.cs.hope.edu!vnopstal
- From: vnopstal@cs.hope.edu (Michael Van Opstall)
- Newsgroups: comp.lang.c++
- Subject: Re: How to make a Complex class
- Date: 1 Jan 1996 21:58:19 GMT
- Organization: Hope College
- Message-ID: <4c9ldr$7e@news.cs.hope.edu>
- References: <4c8kdm$p0q@news.csie.nctu.edu.tw>
- NNTP-Posting-Host: smaug.cs.hope.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- Here's a header for a complex class. I have one completely written. e-mail
- me for more info
-
- class Complex
- {
- friend operator+(Complex c1, Complex c2);
- friend operator-(Complex c1, Complex c2);
- friend operator*(Complex c1, Complex c2);
- friend operator/(Complex c1, Complex c2);
-
- Complex(); // constructs 0+0i
- Complex(double real, double imag);
-
- double mag(Complex c1); // magnitude of vector
-
- private:
- double real, imag;
- }
-
- That's about all you need for the basics. The only tricky part is the mult
- and division operators. The multiplication is just a binomial expansion, but
- division is tricky. Hint: you have to multiply by the conjugate. Note that
- you'll also need to #include <math.h> for the functions necessary to find a
- magnitude.
-
-
- --
- Michael A. Van Opstall -- vnopstal@cs.hope.edu
- http://www.cs.hope.edu/~vnopstal/deal.html - try it
-